package com.atguigu.common.vaild;

import lombok.extern.log4j.Log4j;
import org.springframework.util.CollectionUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program: gulimall
 * @description: 校验
 * @author: liuxvru
 * @create: 2024-02-04 17:36
 **/
public class ListValueConstraintValidator implements ConstraintValidator<ListValue,Integer> {
    ArrayList<Integer> list;
    //初始化方法
    @Override
    public void initialize(ListValue constraintAnnotation) {
        for (int i = 0; i < constraintAnnotation.vals().length; i++) {
            list.add(constraintAnnotation.vals()[i]);
        }
        ConstraintValidator.super.initialize(constraintAnnotation);
    }
    //
    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
        System.out.println(integer);
        if(list==null)return false;
        for (int val : list) {
            if (val == integer) {
                return false;
            }
        }
        return false;
    }
}
